package com.qf.lanzhou.shop.api.service.impl;

import com.qf.lanzhou.shop.api.dao.SerialMapper;
import com.qf.lanzhou.shop.api.service.SerialService;
import com.qf.lanzhou.shop.pojo.entity.Serial;
import com.qf.lanzhou.shop.pojo.qo.SerialQo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author Yeach-chen
 * @ClassName SerialsIml
 */
@Service
public class SerialsIml implements SerialService {
    @Autowired
    private SerialMapper serialMapper;
    @Override
    public List<Serial> getSerial(Long id) throws ParseException {
        List<Serial> serials = serialMapper.getSerials(id);
        for (Serial serial:serials) {
            Date parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(serial.getSerialOrderNno());
            serial.setSerialNum(parse.getTime());
        }
       return serials;
    }

    @Override
    public int deleteSerial(Long id) {
        int result = serialMapper.deleteSerial(id);
        return result;
    }

    @Override
    public List<Serial> serialList(SerialQo serialQo) throws ParseException {
        List<Serial> serials = serialMapper.searchSerials(serialQo);
        for (Serial serial:serials) {
            Date parse = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(serial.getSerialOrderNno());
            serial.setSerialNum(parse.getTime());
        }
        return serials;
    }
}
